package com.jason.bookworm.service.impl;

import com.jason.bookworm.dao.pojo.Book;
import com.jason.bookworm.response.Result;
import com.jason.bookworm.response.StatusEnum;
import com.jason.bookworm.service.BookWareService;
import com.jason.bookworm.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SearchServiceImpl implements SearchService {

    @Autowired
    private BookWareService bookWareService;

    /**
     * @param bookName 书名
     * @return 书籍
     */
    @Override
    public Result<List<Book>> searchByBookName(String bookName) {
        List<Book> books = bookWareService.getBooksByBookName(bookName);
        if (books.isEmpty()) {
            return new Result<>(StatusEnum.GET_ERR, "未找到任何书籍！");
        }
        return new Result<>(StatusEnum.GET_OK,books);
    }

    /**
     * @param author 作者
     * @return 书籍
     */
    @Override
    public Result<List<Book>> searchByAuthor(String author) {
        List<Book> books = bookWareService.getBooksByAuthor(author);
        if (books.isEmpty()) {
            return new Result<>(StatusEnum.GET_ERR, "未找到任何书籍！");
        }
        return new Result<>(StatusEnum.GET_OK,books);
    }

    /**
     * @param publish 出版社
     * @return 书籍
     */
    @Override
    public Result<List<Book>> searchByPublish(String publish) {
        List<Book> books = bookWareService.getBooksByPublishName(publish);
        if (books.isEmpty()) {
            return new Result<>(StatusEnum.GET_ERR, "未找到任何书籍！");
        }
        return new Result<>(StatusEnum.GET_OK,books);
    }
}
